#include <iostream>
#include <ctime>
using namespace std;
void delay(double n)
{
    double start = clock();
    while(true)
    {
        double end = clock();
        if(((end - start)/CLK_TCK) > n)
            break;
    };
}
class Boxer
{
    public:
        Boxer();
        Boxer(char * name,int age, int weight);
        void set(char * name,int age, int weight);
        void intro();
        void introSlow();
        int punch();
        int dodge();
        void dance();
        void biHit();
        Boxer love(Boxer other);
        Boxer operator+ (Boxer other);
        ostream & operator>>( ostream & os);
    private:
        char name[24];
        int age;
        int weight;
        int blood;;
};
Boxer::Boxer()
{
    strcpy(name,"noName");
    age = 0;
    weight = 0;   
}

Boxer::Boxer(char * pname,int page, int pweight)
{
    strcpy(name,pname);
    age = page;
    weight = pweight; 
}
void Boxer::set(char * pname,int page,int pweight)
{
    strcpy(name,pname);
    age = page;
    weight = pweight; 
}
void Boxer::intro()
{
    std::cout<<"Hello everyone! I am "<<name<<". and "<< "I am "<<age<<" years old and I am "<<weight<< " kilograms\n";
}
void Boxer::introSlow()
{
    char *  q = new char[128];
    sprintf(q,"Hello everyone! I am %s,%d years old, and %d kg",name,age,weight);
    char * p = q;
    while(*p != '\0')
    {
        std::cout<<*p++<<std::flush;
        //std::cout<<*p++<<'\a'<<std::flush;
        delay(0.05);
    }
    std::cout<<std::endl;
    delete []q;
}
int Boxer::punch()
{
    int choice = rand()%2;
    std::cout<<name<<" punch "<< (choice==0 ? "left":"right" )<<" <---> ";
    return choice;
}
int Boxer::dodge()
{
    int choice = rand()%2;
    std::cout<<name<<" dodge "<< (choice==0 ? "left":"right")<<std::endl;
    return choice;

}
void Boxer::dance()
{
    std::cout<<name<< " win and dancing"<<std::endl;
}
Boxer Boxer::love(Boxer other)
{
    Boxer child;
    child.set("Tom",1,10);
    return child;
}
Boxer Boxer::operator+(Boxer other)
{
    Boxer child;
    child.set("Tom",1,10);
    return child;
}

ostream & Boxer::operator>>(ostream & os)
{
    os<<"name: "<<name<<" age: "<<age<<" weight: "<<weight<<endl;
    return os;
}

int main()
{
    Boxer telson("Telson",25,100);
    Boxer leuis("Leuis",30,120);
    system("cls");
    telson.introSlow();
    leuis.introSlow();
    std::cout<<std::endl;
    /*
    int score1(0),score2(0);
    for(int i = 0;i<12; i++)
    {
        system("cls");
        std::cout<<"Round "<<i+1<<std::endl; 
        if(telson.punch() != leuis.dodge())
             score1++;
        if(leuis.punch() != telson.dodge())
             score2++;
        std::cout<< score1<<"<---------->"<<score2<<std::endl; 
        std::cout<<std::endl;
        delay(1);
    }
    if(score1>score2)
        telson.dance();
    else
        leuis.dance();
    */
    //Boxer tom = telson.love(leuis);
    Boxer tom = telson + leuis;
    tom.introSlow();
    tom>>cout;
}
